using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace Savviety.ServiceManager.API.Criteria
{
    public class OrExpression : Expression
    {
        readonly List<SimpleExpression> _andExpressions = new List<SimpleExpression>();
        private bool _hasAndCriteria;
        public OrExpression(ICollection<SimpleExpression> expressions):base()       
        {
           
            if (expressions.Count < 2)
                throw new ArgumentException("You must add at least two expressions");
            Root = GetXElement("Or");
            Expressions.AddRange(expressions);
        }

        public void AddAnd(List<SimpleExpression> expressions)
        {
            _andExpressions.AddRange(expressions);
            _hasAndCriteria = true;
        }
        public override XElement ToXElement()
        {
            if (_hasAndCriteria)
            {
                // add or data here
            }
            foreach (var expression in Expressions)
            {
                Root.Add(expression.ToXElement());
            }
            return Root;
        }

    }
}